package com.nsn.das.midas.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.nsn.das.midas.model.mml.data.MMLClassData;
import com.nsn.das.midas.model.mml.letter.MMLClassLetter;
import com.nsn.das.midas.service.MMLClassManager;
import com.nsn.das.midas.service.MMLGroupManager;

@Service("mmlClassManager")
public class MMLClassManagerImpl extends BaseManagerImpl implements MMLClassManager{
	@Resource(name = "mmlGroupManager")
	private MMLGroupManager groupManager;
	
	@Override
	public MMLClassData getMMLClass(long id) throws Exception {
		return getEntity(MMLClassData.class, id);
	}

	/* (non-Javadoc)
	 * @see com.nsn.das.midas.service.MMLClassManager#saveMMLClass(com.nsn.das.midas.model.mml.data.MMLClassData)
	 */
	@Override
	public void saveMMLClass(MMLClassData classData){
		getHibernateTemplate().saveOrUpdate(classData);
	}
	
	@Override
	public List<MMLClassLetter> getAvailableClassLetters() throws Exception {
		List<MMLClassLetter> all = getEntities(MMLClassLetter.class,1,(int)countEntities(MMLClassLetter.class));
		List<MMLClassLetter> availableLetters = new ArrayList<MMLClassLetter>();	
		availableLetters.addAll(all);
		for(MMLClassLetter model : all){
			for(String letter : LETTERS){			
				if(model.getLetter().equals(letter)){
					availableLetters.remove(model);
				}				
			}
		}
		
		return availableLetters;
	}
}
